package com.magazine.bean.pages;

/**
 * 分页类，记载分页相关数据
 * 
 * @author zhugd
 * 
 */
public class DataPage {
	
	private int allPage = 0;// 总页�?

	private int pageNumber = 16;// 每页几条记录

	private int currPage = 0;// 当前页数

	private int allPageNumber = 0;// 总记录数

	private int pageLevel = 2;// 页面横向分层
	
	private int parentPage = 0;//�?属上�?级页面数
	
	public void setParentPage(int parPage){
		this.parentPage = parPage;
	}
	public int getParentPage(){
		return this.parentPage;
	}
	
	public void setPageLevel(int pageLevel){
		this.pageLevel = pageLevel;
	}
	public int getPageLevel(){
		return this.pageLevel;
	}
	/**
	 * 设置总记录数
	 * 
	 * @param ipageNum
	 */
	public void setAllPageNumber(int ipageNum) {
		this.allPageNumber = ipageNum;
	}

	public int getAllPageNumber() {
		if (this.allPageNumber < 0) {
			this.allPageNumber = 0;
		}
		return this.allPageNumber;
	}

	/** 设置每页显示记录�?* */
	public void setPageNumber(int pageNum) {
		this.pageNumber = pageNum;
	}

	public int getPageNumber() {
		if (this.pageNumber < 0) {
			this.pageNumber = 0;
		}
		return this.pageNumber;
	}

	/** 设置总记录数* */
	public void setAllPage(int pageNum) {
		this.allPage = pageNum;
	}

	public int getAllPage() {

		this
				.setAllPage(this.getAllPageNumber() % this.getPageNumber() > 0 ? (this
						.getAllPageNumber() / this.getPageNumber()) + 1
						: this.getAllPageNumber() / this.getPageNumber());
		if (this.allPage < 0) {
			this.allPage = 0;
		}
		return this.allPage;
	}

	/** 每页分行时的记录�?* */
	public int getPageEnter() {
		int iEnter = this.pageNumber % this.pageLevel > 0 ? (this.pageNumber / this.pageLevel) + 1
				: this.pageNumber / this.pageLevel;
		
		if (iEnter <= 0) {
			iEnter = 1;
		}
		return iEnter;
	}

	/** 设置当前页数* */
	public void setCurrPage(int pageNum) {
		this.currPage = pageNum;
	}
	
	public int getCurrPage() {
		
		if (this.currPage >= this.getAllPage()) {
			this.currPage = this.getAllPage()-1 ;
		}
		if (this.currPage < 0) {
			this.currPage = 0;
		}
		return this.currPage;
	}

	public int getNextPage() {
		return this.getCurrPage() + 1;
	}

	public int getPrvPage() {
		return this.getCurrPage() - 1;
	}

	public int getFrist() {
		return 0;
	}

	public int getLast() {
		return this.getAllPage();
	}
}
